const ActionButton = (hook, { Button, Tooltip, Popconfirm, throttle2 }) => {
	return {
		isJiess: true,
		name: 'ActionButton',
		setup({
			onClick,
			tip = '',
			pop = '',
			icon = null,
			text = null,
			// 默认阻止冒泡
			stop = true,
			// 节流时长
			waitTime = 500,
			tipParam = {},
			popParam = {},
			...other
		}) {
			const initButton = (param) => {
				const config = {
					is: Button,
					onClick: e => {
						if (stop) e.stopPropagation();
						// 有浮框，则不绑定处理事件
						if (pop) return;
						// 对按钮默认启用节流功能
						if (typeof onClick === 'function') {
							throttle2(onClick, waitTime);
						}
					},
					...param,
					...other
				};
				if (text) {
					config.children = text;
				} else if (icon) {
					config.icon = icon
					config.circle = true;
					config.style = { fontSize: '22px', padding: '6px' }
				}
				return config;
			};

			const initTip = (param) => {
				return tip ? {
					is: Tooltip,
					content: tip,
					...param,
					...tipParam,
					children: initButton()
				} : initButton(param)
			};
			this.add(pop ? {
				title: pop,
				is: Popconfirm,
				// 使用浮框确认
				onConfirm: onClick,
				// 控制按钮间的间隙
				style: { margin: '0 8px' },
				'confirm-button-text': '确定',
				'cancel-button-text': '取消',
				children: initTip({ slot: 'reference' }),
				...popParam
			} : initTip());
		}
	}
};
export default ActionButton;